using Unity.Mathematics;
using WorldMapBase.Tile.Pool;
using Yoozoo.Libs;

namespace WorldMapBase.Tile
{
    public class TileShowCmd : TileCommandBase,IClass
    {
        public int LayerID;
        public int LodLevel;
        public int TileIndex;
        public int2 WorldCenterPos;

        public void Init(int layerID,int lodLevel,int tileIndex,int2 worldCenterPos)
        {
            LayerID = layerID;
            LodLevel = lodLevel;
            TileIndex = tileIndex;
            WorldCenterPos = worldCenterPos;
        }
        
        public override bool Check()
        {
            //层级过滤
            int curLodLevel = TileDisplayManager.Instance.GetLayerLODLevel(LayerID);
            if (curLodLevel != LodLevel)
            {
                return false;
            }

            if (!TileDisplayManager.Instance.TileInRect(LayerID,LodLevel,TileIndex))
            {
                return false;
            }


            return !TileDisplayManager.Instance.TileIsShowing(LayerID, LodLevel, TileIndex);
        }

        public override void Execute()
        {
            TileDisplayManager.Instance.OnAddTile(this);

#if UNITY_EDITOR
            TileDisplayManager.TileNum++;
#endif
        }

        public override void Recover()
        {
            ClassPoolManager.RecoverTileShowCmd(this);
        }

        public void OnReset()
        {
            LayerID = -1;
            LodLevel = -1;
            TileIndex = -1;
            WorldCenterPos = int2.zero;
        }
    }
}